package com.example.bookrecommendationjava.mapper;

import com.example.bookrecommendationjava.model.Like;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @BelongsProject: book-recommendation-java
 * @BelongsPackage: com.example.bookrecommendationjava.mapper
 * @Author: ZhShy
 * @CreateTime: 2022-03-17 19:51
 * @Description:
 */
@Mapper
public interface LikeMapper {
    @Insert("insert into likelist (userId, bookId) values (${userId}, ${bookId})")
    void insertIntoLike(Integer userId, Integer bookId);

    @Select("select * from likelist where userId=${userId} order by likeId desc")
    List<Like> selectAllFromLikeByUserId(Integer userId);

    @Delete("delete from likelist where userId=${userId} and bookId=${bookId}")
    void deleteFromLikeByUserIdAndBookId(Integer userId, Integer bookId);

    @Select("select bookId from likelist where userId=${userId}  order by bookId asc")
    List<Integer> selectBookIdFromLikeByUserId(Integer userId);

}
